import { isUrl } from '../utils/utils';

const menuData = [
  {
    name: '首页',
    icon: 'table',
    path: 'home/home-page',
  },
  {
    name: '产品管理',
    icon: 'setting',
    path: 'product',
    children: [
      {
        name: '产品列表',
        path: 'product-catalog',
      },
      {
        name: '产品展业',
        path: 'product-acquisition',
      },
    ],
  },
  {
    name: '渠道管理',
    icon: 'setting',
    path: 'channel',
    children: [
      {
        name: '经销商管理',
        path: 'channel-maintenance',
      },
      {
        name: '经销商审核',
        path: 'dealer-audit',
      },
    ],
  },
  {
    name: '客户管理',
    icon: 'setting',
    path: 'customer',
    children: [
      {
        name: '客户维护',
        path: 'customer-management',
      },
      {
        name: '客户分派',
        path: 'platform-assignment',
      },
      {
        name: '客户指派',
        path: 'org-assignment',
      },
    ],
  },
  {
    name: '业务管理',
    icon: 'setting',
    path: 'apply',
    // authority: ['admin', 'user'],
    children: [
      {
        name: '业务列表',
        path: 'applyIndex',
      },
      {
        name: '业务申请',
        path: 'createApplyList',
      },
      {
        name: '业务受理',
        path: 'operateList',
      },
      // {
      //   name: '审批驳回',
      //   path: 'reviewRejectList',
      // },
      {
        name: '申请资料',
        path: 'businessSupplementList',
      },
      {
        name: '签约服务',
        path: 'signContractList',
      },
      {
        name: '放款管理',
        path: 'cashOutList',
      },
      {
        name: '提车服务',
        path: 'pickCarEditorList',
      },
      {
        name: '上报银行',
        path: 'reportBrankList',
      },
      {
        name: '预付费明细',
        path: 'prePay',
      },
      {
        name: '业务补导入',
        path: 'businessImport',
      },
    ],
  },
  {
    name: '风险管理',
    icon: 'setting',
    path: 'risk',
    // authority: ['admin', '1107'],
    children: [
      {
        name: '风险管理',
        path: 'riskInex',
      },
      {
        name: '业务初筛',
        path: 'preCheckList',
      },
      {
        name: '业务初筛单独',
        path: 'alonePreCheckList',
      },
      {
        name: '家访调查',
        path: 'homeVisitList',
      },
      {
        name: '业务初审',
        path: 'checkList',
      },
      {
        name: '业务复审',
        path: 'reviewList',
      },
      {
        name: '提车审核',
        path: 'pickCarList',
      },
    ],
  },
  {
    name: '系统配置',
    icon: 'setting',
    path: 'system',
    children: [
      {
        name: '组织架构维护',
        path: 'structure-maintenance',
      },
      {
        name: '员工管理',
        path: 'employee-management',
      },
      {
        name: '角色管理',
        path: 'role-management',
      },
      {
        name: '消息通知',
        path: 'message-notification',
      },
      {
        name: '流程配置',
        path: 'search',
        children: [
          {
            name: '分配规则制定',
            path: 'allocation-rules',
          },
          {
            name: '任务管理',
            path: 'task-list',
          },
          {
            name: '任务分派',
            path: 'task-dispatch',
          },
        ],
      },
    ],
  },
];

function formatter(data, parentPath = '/', parentAuthority) {
  return data.map(item => {
    let { path } = item;
    if (!isUrl(path)) {
      path = parentPath + item.path;
    }
    const result = {
      ...item,
      path,
      authority: item.authority || parentAuthority,
    };
    if (item.children) {
      result.children = formatter(item.children, `${parentPath}${item.path}/`, item.authority);
    }
    return result;
  });
}

export const getMenuData = () => formatter(menuData);
